import java.util.*;

public class RepeatedDNASequences_Fail {
    public static List<String> findRepeatedDnaSequences(String s) {
ArrayList<String> result = new ArrayList<String>();

        if(s== null || s.length() == 0) return result;
        
        HashMap<Character,Integer> map = new HashMap<Character,Integer>();
        map.put('A',0);
        map.put('C',1);
        map.put('G',2);
        map.put('T',3);

        HashSet<Integer> hashSet = new HashSet<Integer>();
                
        int temp = 0;            
        for(int i=0;i<s.length()-9;i++){
            temp = 0;            
            for(int j=0;j<10;j++){
                temp = temp * 4 + map.get(s.charAt(i+j));
            }
            //System.out.println(temp);
            if(hashSet.contains(temp) && !result.contains(s.substring(i,i+10))){
                result.add(s.substring(i,i+10));
            }
            else {
                hashSet.add(temp);
            }
        }
        
        return result;
    }
    
    public static void main(String[] args) {
        String s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT";
        System.out.println(findRepeatedDnaSequences(s));
    }
}
